<template>
  <div class="detailPost">
    <!-- 1.登录头部导航提示 -->
    <van-nav-bar title="发表评论" fixed>
      <template #left>
        <van-icon
          name="arrow-left"
          size="18"
          @click="$emit('changeIsShowDetailPost', false)"
        />
        <!-- @click="$emit('input',false)" -->
      </template>
    </van-nav-bar>
    <!-- 2.占位 -->
    <div class="zhanwei"></div>
    <van-field
      class="post-field"
      v-model.trim="message"
      rows="2"
      autosize
      type="textarea"
      maxlength="50"
      placeholder="请输入留言"
      show-word-limit
    />
    <!-- @click="onPost" :disabled="!message.length" -->
    <div class="post-btn">
      <van-button
        type="plain"
        class="post-btn"
        @click="$emit('changeIsShowDetailPost', false)"
        >取消</van-button
      >
      <van-button type="success" class="post-btn" @click="detailPostHandler"
        >发布</van-button
      >
    </div>
  </div>
</template>

<script>
import { detailPost } from "@/api/special";
export default {
  name: "detailPost",
  props: {
    Vid: {
      type: Number,
    },
  },
  data() {
    return {
      message: "",
    };
  },
  created() {},
  methods: {
    async detailPostHandler() {
      if (!this.message) {
        return this.$toast.fail("内容不能为空!");
      }
      try {
        // 1. 发送数据 给服务器
        await detailPost({
          content: this.message, //评论内容
          typeId: 1, // 评论 类型
          valueId: this.Vid, //给某个id进行评论;
        });

        //2.执行父组件中的方法 直接渲染 执行父组件中的方法;
        this.$parent.leaningMsgHandler();
        this.$emit("changeIsShowDetailPost", false);
      } catch (err) {
        console.log(err.message);
      }
    },
  },
};
</script>

<style scoped lang="scss">
.detailPost {
  box-sizing: border-box;
  background-color: #fff;
  align-items: center;
  .post-field {
    background-color: #f5f7f9;
  }
  .post-btn {
    width: 150px;
    border: none;
    padding: 0;
    color: #6ba3d8;
    &::before {
      display: none;
    }
  }
}

::v-deep .van-nav-bar__content {
  background-color: rgb(238, 10, 36);
  border: 1px solid rgb(238, 10, 36);
}
::v-deep .van-nav-bar__title.van-ellipsis,
::v-deep .van-icon-arrow-left {
  color: #fff;
}

.zhanwei {
  height: 92px;
}
::v-deep .post-btn {
  display: flex;
  justify-content: space-between;
  width: 100vw !important;
  .post-btn {
    width: 100px;
    justify-content: center;
    align-content: center;
    display: flex;
  }
}
</style>
